package com.wuzhishan.news.controller;

import com.wuzhishan.news.pojo.Result;
import com.wuzhishan.news.service.commentService;
import com.wuzhishan.news.utils.numberTransUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.text.DecimalFormat;
import java.text.ParseException;

@Controller
public class CommentController {
    @Autowired
    private commentService commentService;

    /**
     * 添加评论
     * @param toId
     * @param pid
     * @param text
     * @param session
     * @return
     */
    @RequestMapping("/comment/submit")
    @ResponseBody
    public Result comment(String toId, String pid, String text, HttpSession session){
        //toid:文章ID，pid：针对评论ID（若对该文章评论，则为0），text：评论内容
        Result result = commentService.addComment(numberTransUtil.TransNum(toId)+"",pid,text,session);
        return result;
    }

    @RequestMapping("/comment/list/{articleId}")
    @ResponseBody
    public Object selectPageComment(@PathVariable String articleId,String pageSize,String pn){
        //articleId:文章id，pageSize：每页评论条数，pn：当前页数
        Result result = commentService.selectPageComment(numberTransUtil.TransNum(articleId),pageSize,pn);
        return result.get("data");
    }
}
